package com.andrew.markov.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;

import com.andrew.markov.gui.util.RowHeaderRenderer;

public class StepPanel extends JFrame {

	private static final long serialVersionUID = 7460607334268776563L;
	private JPanel contentPane;
	private JTable table;

	/**
	 * Create the frame.
	 */
	public StepPanel(double[][] poweredMatrix) {
		// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 636, 394);
		this.setLocationRelativeTo(null);

		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		// contentPane.setLayout(new BorderLayout(0, 0));

		initStepTable(poweredMatrix);

	}

	private void initStepTable(double[][] poweredMatrix) {

		Object rowData[][] = new Object[poweredMatrix.length][poweredMatrix.length + 1];
		for (int i = 0; i < poweredMatrix.length; i++) {
			for (int j = 0; j < poweredMatrix.length + 1; j++) {
				rowData[i][j] = "0";
				rowData[i][0] = "State " + (i);
			}
		}

		Object columnNames[] = new Object[poweredMatrix.length + 1];
		for (int i = 0; i < poweredMatrix.length + 1; i++) {
			columnNames[0] = "From \\ To";
			columnNames[i] = "State" + (i - 1);
		}

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(40, 11, 533, 217);
		contentPane.add(scrollPane);

		table = new JTable(rowData, columnNames);
		// table.setBounds(65, 11, 498, 186);
		table.setCellSelectionEnabled(true);
		table.setColumnSelectionAllowed(true);
		table.getColumnModel().getColumn(0)
				.setCellRenderer(new RowHeaderRenderer());// ROW HEADER
		scrollPane.setColumnHeaderView(table);

		JButton btnNewButton = new JButton("New button");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnNewButton.setBounds(26, 267, 152, 53);
		contentPane.add(btnNewButton);

	}

}
